import Vue from 'vue'
import VueRouter from 'vue-router'
import LoginRegister from './modules/LoginRegister'
import TabBar from './modules/TabBar'
import set from './modules/set';
import privateInfo from './modules/praInfo'
import home from './modules/home'
import profile from './modules/profile';
import loginSet from './modules/loginSet'
import store from '../store/index'
 
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location, onResolve, onReject) {
    if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject);
    return originalPush.call(this, location).catch(err => err);
};
Vue.use(VueRouter)


const routes = [
  {
    path: '/',
    redirect: '/login'
  },
  ...TabBar,
  ...LoginRegister,
  ...set,
  ...privateInfo,
  ...home,
  ...profile,
  ...loginSet
]

const router = new VueRouter({
  routes
})
router.beforeEach((to,from,next) => {
  if(to.path=='/register' || to.path=='/login') {
    next()
    return 
  }
  let str = window.sessionStorage.getItem('vuex');
  if(!str){
    next({
      path:'/login'
    })
  }else {
    next()
  }

})


export default router
